/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import util.CommonUtil;

public class DbInfoUpdate {

    private String dateGI;
    private String dateIG;
    private static final String RMS_NAME = "kamus_infoupdate";  //nama RMS
    private static final String SEPARATOR="|";
    private static final String DATE_GI_DEFAULT="1262278800000";    //default tanggal 01/01/2010
    private static final String DATE_IG_DEFAULT="1262278800000";    //default tanggal 01/01/2010

    public DbInfoUpdate() {
    }

    /**
     * ambil data dari RMS
     */
    public void load() {
        String result = Http.readFromRMS(RMS_NAME);
        if(result.length()==0){ // init pertama kali
            save(DATE_GI_DEFAULT, DATE_IG_DEFAULT);
            setDateGI(DATE_GI_DEFAULT);
            setDateIG(DATE_IG_DEFAULT);
            return ;
        }
        String[] arrResult = CommonUtil.splitStr(result, SEPARATOR);
        setDateGI(arrResult[0]);
        setDateIG(arrResult[1]);
    }

    /**
     * menyimpan data ke RMS
     * @param dateGI tanggal update database Gaul-Ind
     * @param dateIG tanggal update database Ind-Gaul
     */
    public void save(String dateGI,String dateIG){
        StringBuffer data = new StringBuffer();
        data.append(dateGI).append(SEPARATOR).append(dateIG);
        Http.saveToRMS(RMS_NAME, data.toString().getBytes(), true);
        setDateGI(dateGI);
        setDateIG(dateIG);
    }

    public String getDateGI() {
        return dateGI;
    }

    public void setDateGI(String dateGI) {
        this.dateGI = dateGI;
    }

    public String getDateIG() {
        return dateIG;
    }

    public void setDateIG(String dateIG) {
        this.dateIG = dateIG;
    }
}
